# Copyright (c) 2018 Presto Labs Pte. Ltd.
# Author: jhkim


class StickyPrice(object):
  def __init__(self, *, buy_model_output, sell_model_output, buy_price_max, sell_price_min):
    self.buy_model_output = buy_model_output
    self.sell_model_output = sell_model_output
    self.buy_price_max = buy_price_max
    self.sell_price_min = sell_price_min

  def get_prices_on_new_bbo(self, *, bid0p, ask0p):
    if self.buy_model_output is None:
      buy_price = None
    else:
      buy_price = bid0p + self.buy_model_output if self.buy_price_max is None \
                  else min(bid0p + self.buy_model_output, self.buy_price_max)
    if self.sell_model_output is None:
      sell_price = None
    else:
      sell_price = \
        ask0p - self.sell_model_output if self.sell_price_min is None \
        else max(ask0p - self.sell_model_output, self.sell_price_min)
    return (buy_price, sell_price)
